package UI;/*
    张昊（java文件）
 
*/

import BLL.ReaderTypeService;
import Entity.Category;
import Utils.TSUtility;

import java.util.List;
import java.util.Scanner;

public class ReaderTypeUI {
    public static void main(String[] args) {
        ui();
    }
    public static void ui(){
        int readerTypeNumber=0;
        String readerTypeName=null;
        int days=0;
        int bookNumber=0;
        double fine=0;
        Scanner sc=new Scanner(System.in);
        boolean bl=true;
        while (bl) {
            System.out.println("************图书管理系统***********");
            System.out.println("************读者类型管理***********");
            System.out.println("1.添加读者类型");
            System.out.println("2.修改读者类型");
            System.out.println("3.查询读者类型");
            System.out.println("4.删除读者类型");
            System.out.println("5.退出");
            System.out.println("************图书类型管理***********");
            System.out.println("************图书管理系统***********");
            System.out.println("请选择:");
            String number = sc.next();
            switch (number){
                case "1":
                    System.out.println("************图书管理系统***********");
                    System.out.println("************添加读者类型***********");
                    System.out.println("请输入读者类型名称:");
                    readerTypeName= TSUtility.readKeyBoard(10,false);
                    Category category = ReaderTypeService.selectReaderTypeName(readerTypeName);
                    if (category!=null){
                        System.out.println("该读者类型已存在！");
                        break;
                    }
                    System.out.println("请输入可借阅天数：");
                    days=TSUtility.readInt();
                    System.out.println("请输入可借阅图书数量：");
                    bookNumber=TSUtility.readInt();
                    System.out.println("请输入逾期罚金(一天)：");
                    fine=TSUtility.readDouble();
                    int i = ReaderTypeService.addReaderType(readerTypeName, days, bookNumber, fine);
                    System.out.println(i+"条记录受到影响！");
                    System.out.println("************添加读者类型***********");
                    System.out.println("************图书管理系统***********");
                    break;
                case "2":
                    System.out.println("************图书管理系统***********");
                    System.out.println("************修改读者类型***********");
                    System.out.println("请输入读者类型编号：");
                    readerTypeNumber=TSUtility.readInt();
                    Category category1 = ReaderTypeService.selectReaderTypeNumber(readerTypeNumber);
                    if (category1==null){
                        System.out.println("系统中没有该编号的读者类型信息！");
                        break;
                    }
                    System.out.println("请输入读者类型名称("+category1.getReadersTypeName()+"):");
                    readerTypeName=TSUtility.readString(10,category1.getReadersTypeName());
                    System.out.println("请输入可借阅天数("+category1.getDays()+")：");
                    days=Integer.parseInt(TSUtility.readString(10,String.valueOf(category1.getDays())));
                    System.out.println("请输入可借阅图书数量("+category1.getBookNumber()+")：");
                    bookNumber=Integer.parseInt(TSUtility.readString(10,String.valueOf(category1.getBookNumber())));
                    System.out.println("请输入逾期罚金(一天)("+category1.getFine()+")：");
                    fine=(double) Integer.parseInt(TSUtility.readString(10,String.valueOf(category1.getFine())));
                    ReaderTypeService.updateReaderType(readerTypeName, days, bookNumber, fine,readerTypeNumber);
                    System.out.println("************修改读者类型***********");
                    System.out.println("************图书管理系统***********");
                    break;
                case "3":
                    System.out.println("************图书管理系统***********");
                    System.out.println("************查询读者类型***********");
                    System.out.println("读者类型编号    读者类型名称   可借阅天数   可借阅数量    逾期罚金（一天）");
                    List<Category> categories = ReaderTypeService.selectReaderType();
                    if (categories.size()==0){
                        System.out.println("系统中无信息！");
                        break;
                    }
                    categories.forEach(System.out::println);
                    System.out.println("************查询读者类型***********");
                    System.out.println("************图书管理系统***********");
                    break;
                case "4":
                    System.out.println("************图书管理系统***********");
                    System.out.println("************删除读者类型***********");
                    System.out.println("请输入读者类型编号：");
                    readerTypeNumber=TSUtility.readInt();
                    Category category4 = ReaderTypeService.selectReaderTypeNumber(readerTypeNumber);
                    if (category4==null){
                        System.out.println("系统中没有该编号的读者类型信息！");
                        break;
                    }
                    int i1 = ReaderTypeService.deleteReaderType(readerTypeNumber);
                    System.out.println(i1+"条数据受到影响！");
                    System.out.println("************删除读者类型***********");
                    System.out.println("************图书管理系统***********");
                    break;
                case "5":bl=false;break;
                default:
                    System.out.println("没有该选项！");
                    break;
            }
        }
    }
}
